/**
 * "Yet Another Multicolumn Layout" - YAML CSS Framework
 *
 * (en) Workaround for IE8 und Webkit browsers to fix focus problems when using skiplinks
 * (de) Workaround für IE8 und Webkit browser, um den Focus zu korrigieren, bei Verwendung von Skiplinks
 *
 * @note			inspired by Paul Ratcliffe's article
 *					http://www.communis.co.uk/blog/2009-06-02-skip-links-chrome-safari-and-added-wai-aria
 *                  Many thanks to Mathias Schäfer (http://molily.de/) for his code improvements
 *
 * @copyright       Copyright 2005-2012, Dirk Jesse
 * @license         CC-BY 2.0 (http://creativecommons.org/licenses/by/2.0/),
 *                  YAML-CDL (http://www.yaml.de/license.html)
 * @link            http://www.yaml.de
 * @package         yaml
 * @version         4.0+
 * @revision        $Revision: 617 $
 * @lastmodified    $Date: 2012-01-05 23:56:54 +0100 (Do, 05 Jan 2012) $
 */

(function () {
    var YAML_focusFix = {
        skipClass : 'ym-skip',

        init : function () {
            var userAgent = navigator.userAgent.toLowerCase();
            var	is_webkit = userAgent.indexOf('webkit') > -1;
            var	is_ie = userAgent.indexOf('msie') > -1;

            if (is_webkit || is_ie) {
                var body = document.body,
                    handler = YAML_focusFix.click;
                if (body.addEventListener) {
                    body.addEventListener('click', handler, false);
                } else if (body.attachEvent) {
                    body.attachEvent('onclick', handler);
                }
            }
        },

        trim : function (str) {
            return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
        },

        click : function (e) {
            e = e || window.event;
            var target = e.target || e.srcElement;
            var a = target.className.split(' ');

            for (var i=0; i < a.length; i++) {
                var cls = YAML_focusFix.trim(a[i]);
                if ( cls === YAML_focusFix.skipClass) {
                    YAML_focusFix.focus(target);
                    break;
                }
            }
        },

        focus : function (link) {
            if (link.href) {
                var href = link.href,
                    id = href.substr(href.indexOf('#') + 1),
                    target = document.getElementById(id);
                if (target) {
                    target.setAttribute("tabindex", "-1");
                    target.focus();
                }
            }
        }
    };
    YAML_focusFix.init();
})();/*
 * Snippet :: jQuery Syntax Highlighter v2.0.0
 * http://steamdev.com/snippet
 *
 * Copyright 2011, SteamDev
 * Released under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Date: Wed Jan 19, 2011
 */

(function($) {

    //enables console.log() in all browsers for error messages
    window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments))}};

    $.fn.snippet = function(language,settings) {

        if(typeof language == "object"){settings = language;}

        if(typeof language == "string"){
            language = language.toLowerCase();
        }

        var defaults = {
            style:"random",
            showNum:true,
            transparent:false,
            collapse:false,
            menu:true,
            showMsg:"Expand Code",
            hideMsg:"Collapse Code",
            clipboard:"",
            startCollapsed:true,
            startText:false,
            box:"",
            boxColor:"",
            boxFill:""
        };

        // array containing all style names
        var styleArr = ["acid","berries-dark","berries-light","bipolar","blacknblue","bright","contrast","darkblue","darkness","desert","dull","easter","emacs","golden","greenlcd","ide-anjuta","ide-codewarrior","ide-devcpp","ide-eclipse","ide-kdev","ide-msvcpp","kwrite","matlab","navy","nedit","neon","night","pablo","peachpuff","print","rand01","the","typical","vampire","vim","vim-dark","whatis","whitengrey","zellner"];

        if(settings){$.extend(defaults,settings)}

        return this.each(function() {

            // variable containing the style to be used
            var useStyle = defaults.style.toLowerCase();
            if(defaults.style == "random"){
                var randomnumber=Math.floor(Math.random()*(styleArr.length));
                useStyle = styleArr[randomnumber];
            }

            // variable containing the selected node
            var o = $(this);

            // the name of the selected node
            var node = this.nodeName.toLowerCase();

            // if the node is indeed a <pre> element...
            if(node == "pre"){

                // saves the original html as a data on the node
                if(o.data('orgHtml')==undefined || o.data('orgHtml')==null){
                    var orgHtml = o.html();
                    o.data('orgHtml',orgHtml);
                }

                // if node IS NOT an existing Snippet...
                if(!o.parent().hasClass("snippet-wrap")){

                    // if language is NOT a string...
                    if(typeof language != "string"){
                        if(o.attr('class').length>0){var errclass=" class=\""+o.attr('class')+"\""}else{var errclass="";}
                        if(o.attr('id').length>0){var errid=" id=\""+o.attr('id')+"\""}else{var errid="";}
                        var error = "Snippet Error: You must specify a language on inital usage of Snippet. Reference <pre"+errclass+errid+">";
                        console.log(error);
                        return false;
                    }

                    o.addClass("sh_"+language).addClass("snippet-formatted").wrap("<div class='snippet-container' style='"+o.attr('style')+";'><div class='sh_"+useStyle+" snippet-wrap'></div></div>");
                    o.removeAttr('style');
                    sh_highlightDocument();

                    // build an ordered list if showNum is true
                    if(defaults.showNum){
                        var newhtml = o.html();
                        newhtml=newhtml.replace(/\n/g, "</li><li>");
                        newhtml="<ol class='snippet-num'><li>"+newhtml+"</li></ol>";
                        while(newhtml.indexOf("<li></li></ol>") != -1){
                            newhtml=newhtml.replace("<li></li></ol>","</ol>");
                        }
                    }
                    // build an unordered list if showNum is false
                    else {
                        var newhtml = o.html();
                        newhtml=newhtml.replace(/\n/g, "</li><li>");
                        newhtml="<ul class='snippet-no-num'><li>"+newhtml+"</li></ul>";
                        while(newhtml.indexOf("<li></li></ul>") != -1){
                            newhtml=newhtml.replace("<li></li></ul>","</ul>");
                        }
                    }

                    // normalizes tab space by replacing them with 4 non-breaking spaces
                    newhtml=newhtml.replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;");


                    // insert highlighted code into <pre> element
                    o.html(newhtml);

                    // cleans up the highlighted html
                    while(o.find("li").eq(0).html() == ""){
                        o.find("li").eq(0).remove();
                    }
                    o.find("li").each(function(){
                        if($(this).html().length<2){
                            var rep = ($(this).html()).replace(/\s/g,"");
                            if(rep==""){
                                if($.browser.opera){
                                    $(this).html("&nbsp;");
                                } else {
                                    $(this).html("<span style='display:none;'>&nbsp;</span>");
                                }
                            }
                        }
                    });

                    // builds text-only view and hover menu
                    var txtOnly = "<pre class='snippet-textonly sh_sourceCode' style='display:none;'>"+o.data('orgHtml')+"</pre>";
                    var controls = "<div class='snippet-menu sh_sourceCode' style='display:none;'><pre>"
                        +"<a class='snippet-copy' href='#'>copy</a>"
                        +"<a class='snippet-text' href='#'>text</a>"
                        +"<a class='snippet-window' href='#'>pop-up</a>"
                        +"</pre></div>";

                    o.parent().append(txtOnly);
                    o.parent().prepend(controls);
                    o.parent().hover(function(){$(this).find('.snippet-menu').fadeIn("fast");},function(){$(this).find('.snippet-menu').fadeOut("fast");});

                    // builds clipboard
                    if(defaults.clipboard!="" && defaults.clipboard!=false){
                        var cpy = o.parent().find('a.snippet-copy');
                        cpy.show();
                        cpy.parents('.snippet-menu').show();
                        var txt = o.parents('.snippet-wrap').find('.snippet-textonly').text();
                        ZeroClipboard.setMoviePath(defaults.clipboard);
                        var clip = new ZeroClipboard.Client();
                        clip.setText(txt);
                        clip.glue(cpy[0], cpy.parents('.snippet-menu')[0]);
                        clip.addEventListener( 'complete', function(client, text) {
                            if(text.length > 500){
                                text = text.substr(0,500)+"...\n\n("+(text.length-500)+" characters not shown)";
                            }
                            alert("Copied text to clipboard:\n\n " + text );
                        });

                        cpy.parents('.snippet-menu').hide();

                    } else {
                        o.parent().find('a.snippet-copy').hide();
                    }

                    // click event for text-only view
                    o.parent().find("a.snippet-text").click(function(){
                        var org = $(this).parents('.snippet-wrap').find('.snippet-formatted');
                        var txt = $(this).parents('.snippet-wrap').find('.snippet-textonly');
                        org.toggle();
                        txt.toggle();

                        if(txt.is(':visible')){
                            $(this).html("html");
                        } else {
                            $(this).html("text");
                        }
                        $(this).blur();
                        return false;
                    });

                    // click event for popup view
                    o.parent().find("a.snippet-window").click(function(){
                        var txt = $(this).parents('.snippet-wrap').find('.snippet-textonly').html();
                        snippetPopup(txt);
                        $(this).blur();
                        return false;
                    });

                    // disables menu
                    if(!defaults.menu){
                        o.prev('.snippet-menu').find('pre,.snippet-clipboard').hide();
                    }

                    // collapse functionality
                    if(defaults.collapse){
                        var styleClass = o.parent().attr('class');
                        var collapseShow = "<div class='snippet-reveal "+styleClass+"'><pre class='sh_sourceCode'><a href='#' class='snippet-toggle'>"+defaults.showMsg+"</a></pre></div>";
                        var collapseHide = "<div class='sh_sourceCode snippet-hide'><pre><a href='#' class='snippet-revealed snippet-toggle'>"+defaults.hideMsg+"</a></pre></div>";

                        o.parents('.snippet-container').append(collapseShow);
                        o.parent().append(collapseHide);

                        var root = o.parents('.snippet-container');
                        if(defaults.startCollapsed){
                            root.find('.snippet-reveal').show();
                            root.find('.snippet-wrap').eq(0).hide();
                        } else {
                            root.find('.snippet-reveal').hide();
                            root.find('.snippet-wrap').eq(0).show();
                        }

                        root.find('a.snippet-toggle').click(function(){
                            root.find('.snippet-wrap').toggle();
                            return false;
                        });

                    }

                    // makes snippet background transparent
                    if(defaults.transparent){
                        var styleObj = {"background-color":"transparent","box-shadow":"none","-moz-box-shadow":"none","-webkit-box-shadow":"none"}
                        o.css(styleObj);
                        o.next(".snippet-textonly").css(styleObj);
                        o.parents('.snippet-container').find('.snippet-reveal pre').css(styleObj);
                    }

                    // starts snippet on text-only view
                    if(defaults.startText){
                        o.hide();
                        o.next(".snippet-textonly").show();
                        o.parent().find(".snippet-text").html("html");

                    }

                    // boxes in specified lines of code
                    if(defaults.box!=""){
                        var spacer = "<span class='box-sp'>&nbsp;</span>";
                        var boxNums = defaults.box.split(',');
                        for(var i=0;i<boxNums.length;i++){
                            var boxNum = boxNums[i];
                            if(boxNum.indexOf('-')==-1){
                                boxNum = parseFloat(boxNum)-1;
                                o.find("li").eq(boxNum).addClass('box').prepend(spacer);
                            } else {
                                var numStart = parseFloat(boxNum.split('-')[0])-1;
                                var numEnd = parseFloat(boxNum.split('-')[1])-1;
                                if(numStart<numEnd){
                                    o.find("li").eq(numStart).addClass('box box-top').prepend(spacer);
                                    o.find("li").eq(numEnd).addClass('box box-bot').prepend(spacer);
                                    for(var x=numStart+1; x<numEnd; x++){
                                        o.find("li").eq(x).addClass('box box-mid').prepend(spacer);
                                    }
                                } else if (numStart==numEnd){
                                    o.find("li").eq(numStart).addClass('box').prepend(spacer);
                                }
                            }

                        }

                        // sets the color of the box
                        if(defaults.boxColor!=""){
                            o.find("li.box").css('border-color',defaults.boxColor);
                        }

                        // sets the fill (background color) of the box
                        if(defaults.boxFill!=""){
                            o.find("li.box, li.box-top, li.box-mid, li.box-bot").addClass('box-bg').css('background-color',defaults.boxFill);
                        }

                        if($.browser.webkit){
                            o.find(".snippet-num li.box").css('margin-left','-3.3em');
                            o.find(".snippet-num li .box-sp").css('width','21px');
                        }

                    }

                    // adds a css class to all links in the snippet so they are themed properly
                    o.parents('.snippet-container').find("a").addClass("sh_url");

                }
                // if node IS an existing Snippet...
                else {

                    // set new style classes, remove boxes
                    o.parent().attr("class","sh_"+useStyle+" snippet-wrap");
                    o.parents('.snippet-container').find('.snippet-reveal').attr("class","sh_"+useStyle+" snippet-wrap snippet-reveal");
                    o.find("li.box, li.box-top, li.box-mid, li.box-bot").removeAttr('style').removeAttr('class');
                    o.find("li .box-sp").remove();

                    // set background to transparent
                    if(defaults.transparent){
                        var styleObj = {"background-color":"transparent","box-shadow":"none","-moz-box-shadow":"none","-webkit-box-shadow":"none"}
                        o.css(styleObj);
                        o.next(".snippet-textonly").css(styleObj);
                        o.parents('.snippet-container').find('.snippet-hide pre').css(styleObj);
                    }
                    // remove transparency
                    else {
                        var styleObj = {"background-color":"","box-shadow":"","-moz-box-shadow":"","-webkit-box-shadow":""}
                        o.css(styleObj);
                        o.next(".snippet-textonly").css(styleObj);
                        o.parents('.snippet-container').find('.snippet-reveal pre').css(styleObj);
                    }

                    // show numbers by switching <ul> to <ol>
                    if(defaults.showNum){

                        var list = o.find("li").eq(0).parent();
                        if(list.hasClass("snippet-no-num")){
                            list.wrap("<ol class='snippet-num'></ol>");
                            var li = o.find("li").eq(0);
                            li.unwrap();
                        }
                    }
                    // hide numbers by switching <ol> to <ul>
                    else {
                        var list = o.find("li").eq(0).parent();
                        if(list.hasClass("snippet-num")){
                            list.wrap("<ul class='snippet-no-num'></ul>");
                            var li = o.find("li").eq(0);
                            li.unwrap();
                        }
                    }

                    // box in specified lines
                    if(defaults.box!=""){
                        var spacer = "<span class='box-sp'>&nbsp;</span>";
                        var boxNums = defaults.box.split(',');
                        for(var i=0;i<boxNums.length;i++){
                            var boxNum = boxNums[i];
                            if(boxNum.indexOf('-')==-1){
                                boxNum = parseFloat(boxNum)-1;
                                o.find("li").eq(boxNum).addClass('box').prepend(spacer);
                            } else {
                                var numStart = parseFloat(boxNum.split('-')[0])-1;
                                var numEnd = parseFloat(boxNum.split('-')[1])-1;
                                if(numStart<numEnd){
                                    o.find("li").eq(numStart).addClass('box box-top').prepend(spacer);
                                    o.find("li").eq(numEnd).addClass('box box-bot').prepend(spacer);
                                    for(var x=numStart+1; x<numEnd; x++){
                                        o.find("li").eq(x).addClass('box box-mid').prepend(spacer);
                                    }
                                } else if (numStart==numEnd){
                                    o.find("li").eq(numStart).addClass('box').prepend(spacer);
                                }
                            }

                        }

                        if(defaults.boxColor!=""){
                            o.find("li.box").css('border-color',defaults.boxColor);
                        }

                        if(defaults.boxFill!=""){
                            o.find("li.box").addClass('box-bg').css('background-color',defaults.boxFill);
                        }

                        if($.browser.webkit){
                            o.find(".snippet-num li.box").css('margin-left','-3.3em');
                            o.find(".snippet-num li .box-sp").css('width','21px');
                        }

                    }



                    sh_highlightDocument();

                    // show/hide hover menu
                    if(!defaults.menu){
                        o.prev('.snippet-menu').find('pre,.snippet-clipboard').hide();
                    } else {
                        o.prev('.snippet-menu').find('pre,.snippet-clipboard').show();
                    }

                }

            } else {
                var error = "Snippet Error: Sorry, Snippet only formats '<pre>' elements. '<"+node+">' elements are currently unsupported.";
                console.log(error);
                return false;
            }

        });

    };

})(jQuery);


// snippet new window popup function
function snippetPopup(content) {
    top.consoleRef=window.open('','myconsole',
        'width=600,height=300'
            +',left=50,top=50'
            +',menubar=0'
            +',toolbar=0'
            +',location=0'
            +',status=0'
            +',scrollbars=1'
            +',resizable=1');
    top.consoleRef.document.writeln(
        '<html><head><title>Snippet :: Code View :: '+location.href+'</title></head>'
            +'<body bgcolor=white onLoad="self.focus()">'
            +'<pre>'+content+'</pre>'
            +'</body></html>'
    );
    top.consoleRef.document.close();
}





// ZeroClipboard
// Simple Set Clipboard System
// Author: Joseph Huckaby

var ZeroClipboard = {

    version: "1.0.7",
    clients: {}, // registered upload clients on page, indexed by id
    moviePath: 'ZeroClipboard.swf', // URL to movie
    nextId: 1, // ID of next movie

    $: function(thingy) {
        // simple DOM lookup utility function
        if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
        if (!thingy.addClass) {
            // extend element with a few useful methods
            thingy.hide = function() { this.style.display = 'none'; };
            thingy.show = function() { this.style.display = ''; };
            thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
            thingy.removeClass = function(name) {
                var classes = this.className.split(/\s+/);
                var idx = -1;
                for (var k = 0; k < classes.length; k++) {
                    if (classes[k] == name) { idx = k; k = classes.length; }
                }
                if (idx > -1) {
                    classes.splice( idx, 1 );
                    this.className = classes.join(' ');
                }
                return this;
            };
            thingy.hasClass = function(name) {
                return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
            };
        }
        return thingy;
    },

    setMoviePath: function(path) {
        // set path to ZeroClipboard.swf
        this.moviePath = path;
    },

    dispatch: function(id, eventName, args) {
        // receive event from flash movie, send to client
        var client = this.clients[id];
        if (client) {
            client.receiveEvent(eventName, args);
        }
    },

    register: function(id, client) {
        // register new client to receive events
        this.clients[id] = client;
    },

    getDOMObjectPosition: function(obj, stopObj) {
        // get absolute coordinates for dom element
        var info = {
            left: 0,
            top: 0,
            width: obj.width ? obj.width : obj.offsetWidth,
            height: obj.height ? obj.height : obj.offsetHeight
        };

        while (obj && (obj != stopObj)) {
            info.left += obj.offsetLeft;
            info.top += obj.offsetTop;
            obj = obj.offsetParent;
        }

        return info;
    },

    Client: function(elem) {
        // constructor for new simple upload client
        this.handlers = {};

        // unique ID
        this.id = ZeroClipboard.nextId++;
        this.movieId = 'ZeroClipboardMovie_' + this.id;

        // register client with singleton to receive flash events
        ZeroClipboard.register(this.id, this);

        // create movie
        if (elem) this.glue(elem);
    }
};

ZeroClipboard.Client.prototype = {

    id: 0, // unique ID for us
    ready: false, // whether movie is ready to receive events or not
    movie: null, // reference to movie object
    clipText: '', // text to copy to clipboard
    handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
    cssEffects: true, // enable CSS mouse effects on dom container
    handlers: null, // user event handlers

    glue: function(elem, appendElem, stylesToAdd) {
        // glue to DOM element
        // elem can be ID or actual DOM element object
        this.domElement = ZeroClipboard.$(elem);

        // float just above object, or zIndex 99 if dom element isn't set
        var zIndex = 99;
        if (this.domElement.style.zIndex) {
            zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
        }

        if (typeof(appendElem) == 'string') {
            appendElem = ZeroClipboard.$(appendElem);
        }
        else if (typeof(appendElem) == 'undefined') {
            appendElem = document.getElementsByTagName('body')[0];
        }

        // find X/Y position of domElement
        var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);

        // create floating DIV above element
        this.div = document.createElement('div');
        this.div.className = "snippet-clipboard";
        var style = this.div.style;
        style.position = 'absolute';
        style.left = '' + box.left + 'px';
        style.top = '' + box.top + 'px';
        style.width = '' + box.width + 'px';
        style.height = '' + box.height + 'px';
        style.zIndex = zIndex;

        if (typeof(stylesToAdd) == 'object') {
            for (addedStyle in stylesToAdd) {
                style[addedStyle] = stylesToAdd[addedStyle];
            }
        }

        // style.backgroundColor = '#f00'; // debug

        appendElem.appendChild(this.div);

        this.div.innerHTML = this.getHTML( box.width, box.height );
    },

    getHTML: function(width, height) {
        // return HTML for movie
        var html = '';
        var flashvars = 'id=' + this.id +
            '&width=' + width +
            '&height=' + height;

        if (navigator.userAgent.match(/MSIE/)) {
            // IE gets an OBJECT tag
            var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
            html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
        }
        else {
            // all other browsers get an EMBED tag
            html += '<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
        }
        return html;
    },

    hide: function() {
        // temporarily hide floater offscreen
        if (this.div) {
            this.div.style.left = '-2000px';
        }
    },

    show: function() {
        // show ourselves after a call to hide()
        this.reposition();
    },

    destroy: function() {
        // destroy control and floater
        if (this.domElement && this.div) {
            this.hide();
            this.div.innerHTML = '';

            var body = document.getElementsByTagName('body')[0];
            try { body.removeChild( this.div ); } catch(e) {;}

            this.domElement = null;
            this.div = null;
        }
    },

    reposition: function(elem) {
        // reposition our floating div, optionally to new container
        // warning: container CANNOT change size, only position
        if (elem) {
            this.domElement = ZeroClipboard.$(elem);
            if (!this.domElement) this.hide();
        }

        if (this.domElement && this.div) {
            var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
            var style = this.div.style;
            style.left = '' + box.left + 'px';
            style.top = '' + box.top + 'px';
        }
    },

    setText: function(newText) {
        // set text to be copied to clipboard
        this.clipText = newText;
        if (this.ready){ this.movie.setText(newText);}
    },

    addEventListener: function(eventName, func) {
        // add user event listener for event
        // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
        eventName = eventName.toString().toLowerCase().replace(/^on/, '');
        if (!this.handlers[eventName]){ this.handlers[eventName] = [];}
        this.handlers[eventName].push(func);
    },

    setHandCursor: function(enabled) {
        // enable hand cursor (true), or default arrow cursor (false)
        this.handCursorEnabled = enabled;
        if (this.ready){ this.movie.setHandCursor(enabled);}
    },

    setCSSEffects: function(enabled) {
        // enable or disable CSS effects on DOM container
        this.cssEffects = !!enabled;
    },

    receiveEvent: function(eventName, args) {
        // receive event from flash
        eventName = eventName.toString().toLowerCase().replace(/^on/, '');

        // special behavior for certain events
        switch (eventName) {
            case 'load':
                // movie claims it is ready, but in IE this isn't always the case...
                // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
                this.movie = document.getElementById(this.movieId);
                if (!this.movie) {
                    var self = this;
                    setTimeout( function() { self.receiveEvent('load', null); }, 1 );
                    return;
                }

                // firefox on pc needs a "kick" in order to set these in certain cases
                if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
                    var self = this;
                    setTimeout( function() { self.receiveEvent('load', null); }, 100 );
                    this.ready = true;
                    return;
                }

                this.ready = true;
                try{
                    this.movie.setText( this.clipText );
                }catch(e){}
                try{
                    this.movie.setHandCursor( this.handCursorEnabled );
                }catch(e){}
                break;

            case 'mouseover':
                if (this.domElement && this.cssEffects) {
                    this.domElement.addClass('hover');
                    if (this.recoverActive){ this.domElement.addClass('active');}
                }
                break;

            case 'mouseout':
                if (this.domElement && this.cssEffects) {
                    this.recoverActive = false;
                    if (this.domElement.hasClass('active')) {
                        this.domElement.removeClass('active');
                        this.recoverActive = true;
                    }
                    this.domElement.removeClass('hover');
                }
                break;

            case 'mousedown':
                if (this.domElement && this.cssEffects) {
                    this.domElement.addClass('active');
                }
                break;

            case 'mouseup':
                if (this.domElement && this.cssEffects) {
                    this.domElement.removeClass('active');
                    this.recoverActive = false;
                }
                break;
        } // switch eventName

        if (this.handlers[eventName]) {
            for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
                var func = this.handlers[eventName][idx];

                if (typeof(func) == 'function') {
                    // actual function reference
                    func(this, args);
                }
                else if ((typeof(func) == 'object') && (func.length == 2)) {
                    // PHP style object + method, i.e. [myObject, 'myMethod']
                    func[0][ func[1] ](this, args);
                }
                else if (typeof(func) == 'string') {
                    // name of function
                    window[func](this, args);
                }
            } // foreach event handler defined
        } // user defined handler for event
    }

};


/* SHJS */
/* Copyright (C) 2007, 2008 gnombat@users.sourceforge.net */
/* License: http://shjs.sourceforge.net/doc/gplv3.html */

if(!this.sh_languages){this.sh_languages={}}var sh_requests={};function sh_isEmailAddress(a){if(/^mailto:/.test(a)){return false}return a.indexOf("@")!==-1}function sh_setHref(b,c,d){var a=d.substring(b[c-2].pos,b[c-1].pos);if(a.length>=2&&a.charAt(0)==="<"&&a.charAt(a.length-1)===">"){a=a.substr(1,a.length-2)}if(sh_isEmailAddress(a)){a="mailto:"+a}b[c-2].node.href=a}function sh_konquerorExec(b){var a=[""];a.index=b.length;a.input=b;return a}function sh_highlightString(B,o){if(/Konqueror/.test(navigator.userAgent)){if(!o.konquered){for(var F=0;F<o.length;F++){for(var H=0;H<o[F].length;H++){var G=o[F][H][0];if(G.source==="$"){G.exec=sh_konquerorExec}}}o.konquered=true}}var N=document.createElement("a");var q=document.createElement("span");var A=[];var j=0;var n=[];var C=0;var k=null;var x=function(i,a){var p=i.length;if(p===0){return}if(!a){var Q=n.length;if(Q!==0){var r=n[Q-1];if(!r[3]){a=r[1]}}}if(k!==a){if(k){A[j++]={pos:C};if(k==="sh_url"){sh_setHref(A,j,B)}}if(a){var P;if(a==="sh_url"){P=N.cloneNode(false)}else{P=q.cloneNode(false)}P.className=a;A[j++]={node:P,pos:C}}}C+=p;k=a};var t=/\r\n|\r|\n/g;t.lastIndex=0;var d=B.length;while(C<d){var v=C;var l;var w;var h=t.exec(B);if(h===null){l=d;w=d}else{l=h.index;w=t.lastIndex}var g=B.substring(v,l);var M=[];for(;;){var I=C-v;var D;var y=n.length;if(y===0){D=0}else{D=n[y-1][2]}var O=o[D];var z=O.length;var m=M[D];if(!m){m=M[D]=[]}var E=null;var u=-1;for(var K=0;K<z;K++){var f;if(K<m.length&&(m[K]===null||I<=m[K].index)){f=m[K]}else{var c=O[K][0];c.lastIndex=I;f=c.exec(g);m[K]=f}if(f!==null&&(E===null||f.index<E.index)){E=f;u=K;if(f.index===I){break}}}if(E===null){x(g.substring(I),null);break}else{if(E.index>I){x(g.substring(I,E.index),null)}var e=O[u];var J=e[1];var b;if(J instanceof Array){for(var L=0;L<J.length;L++){b=E[L+1];x(b,J[L])}}else{b=E[0];x(b,J)}switch(e[2]){case -1:break;case -2:n.pop();break;case -3:n.length=0;break;default:n.push(e);break}}}if(k){A[j++]={pos:C};if(k==="sh_url"){sh_setHref(A,j,B)}k=null}C=w}return A}function sh_getClasses(d){var a=[];var b=d.className;if(b&&b.length>0){var e=b.split(" ");for(var c=0;c<e.length;c++){if(e[c].length>0){a.push(e[c])}}}return a}function sh_addClass(c,a){var d=sh_getClasses(c);for(var b=0;b<d.length;b++){if(a.toLowerCase()===d[b].toLowerCase()){return}}d.push(a);c.className=d.join(" ")}function sh_extractTagsFromNodeList(c,a){var f=c.length;for(var d=0;d<f;d++){var e=c.item(d);switch(e.nodeType){case 1:if(e.nodeName.toLowerCase()==="br"){var b;if(/MSIE/.test(navigator.userAgent)){b="\r"}else{b="\n"}a.text.push(b);a.pos++}else{a.tags.push({node:e.cloneNode(false),pos:a.pos});sh_extractTagsFromNodeList(e.childNodes,a);a.tags.push({pos:a.pos})}break;case 3:case 4:a.text.push(e.data);a.pos+=e.length;break}}}function sh_extractTags(c,b){var a={};a.text=[];a.tags=b;a.pos=0;sh_extractTagsFromNodeList(c.childNodes,a);return a.text.join("")}function sh_mergeTags(d,f){var a=d.length;if(a===0){return f}var c=f.length;if(c===0){return d}var i=[];var e=0;var b=0;while(e<a&&b<c){var h=d[e];var g=f[b];if(h.pos<=g.pos){i.push(h);e++}else{i.push(g);if(f[b+1].pos<=h.pos){b++;i.push(f[b]);b++}else{i.push({pos:h.pos});f[b]={node:g.node.cloneNode(false),pos:h.pos}}}}while(e<a){i.push(d[e]);e++}while(b<c){i.push(f[b]);b++}return i}function sh_insertTags(k,h){var g=document;var l=document.createDocumentFragment();var e=0;var d=k.length;var b=0;var j=h.length;var c=l;while(b<j||e<d){var i;var a;if(e<d){i=k[e];a=i.pos}else{a=j}if(a<=b){if(i.node){var f=i.node;c.appendChild(f);c=f}else{c=c.parentNode}e++}else{c.appendChild(g.createTextNode(h.substring(b,a)));b=a}}return l}function sh_highlightElement(d,g){sh_addClass(d,"sh_sourceCode");var c=[];var e=sh_extractTags(d,c);var f=sh_highlightString(e,g);var b=sh_mergeTags(c,f);var a=sh_insertTags(b,e);while(d.hasChildNodes()){d.removeChild(d.firstChild)}d.appendChild(a)}function sh_getXMLHttpRequest(){if(window.ActiveXObject){return new ActiveXObject("Msxml2.XMLHTTP")}else{if(window.XMLHttpRequest){return new XMLHttpRequest()}}throw"No XMLHttpRequest implementation available"}function sh_load(language,element,prefix,suffix){if(language in sh_requests){sh_requests[language].push(element);return}sh_requests[language]=[element];var request=sh_getXMLHttpRequest();var url=prefix+"sh_"+language+suffix;request.open("GET",url,true);request.onreadystatechange=function(){if(request.readyState===4){try{if(!request.status||request.status===200){eval(request.responseText);var elements=sh_requests[language];for(var i=0;i<elements.length;i++){sh_highlightElement(elements[i],sh_languages[language])}}else{throw"HTTP error: status "+request.status}}finally{request=null}}};request.send(null)}




function sh_highlightDocument(prefix, suffix) {
    var nodeList = document.getElementsByTagName('pre');
    for (var i = 0; i < nodeList.length; i++) {
        var element = nodeList.item(i);
        var htmlClasses = element.className.toLowerCase();
        var htmlClass = htmlClasses.replace(/sh_sourcecode/g,'');
        if(htmlClass.indexOf("sh_")!=-1){htmlClass=htmlClass.match(/(\bsh_)\w+\b/g)[0];}
        if (htmlClasses.indexOf('sh_sourcecode') != -1) {continue;}
        if (htmlClass.substr(0, 3) === 'sh_') {
            var language = htmlClass.substring(3);
            if (language in sh_languages) {
                sh_highlightElement(element, sh_languages[language]);
            } else if (typeof(prefix) === 'string' && typeof(suffix) === 'string') {
                sh_load(language, element, prefix, suffix);
            } else {
                console.log('Found <pre> element with class="' + htmlClass + '", but no such language exists');
                continue;
            }
            break;
        }
    }
}

/* CSS language (http://shjs.sourceforge.net/lang/sh_css.min.js) */
if(!this.sh_languages){this.sh_languages={}}sh_languages.css=[[[/\/\/\//g,"sh_comment",1],[/@/g,"sh_comment",1],[/\/\//g,"sh_comment",7],[/\/\*\*/g,"sh_comment",8],[/\/\*/g,"sh_comment",9],[/(?:\.|#)[A-Za-z0-9_:\- >\[\]\(\)+\*=",]+/g,"sh_selector",-1],[/\{/g,"sh_cbracket",10,1],[/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,"sh_symbol",-1]],[[/$/g,null,-2],[/(?:<?)[A-Za-z0-9_\.\/\-_~]+@[A-Za-z0-9_\.\/\-_~]+(?:>?)|(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_~]+(?:>?)/g,"sh_url",-1],[/<\?xml/g,"sh_preproc",2,1],[/<!DOCTYPE/g,"sh_preproc",4,1],[/<!--/g,"sh_comment",5],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",6,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,"sh_keyword",6,1],[/@[A-Za-z]+/g,"sh_type",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/\?>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/\\(?:\\|")/g,null,-1],[/"/g,"sh_string",-2]],[[/>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/-->/g,"sh_comment",-2],[/<!--/g,"sh_comment",5]],[[/(?:\/)?>/g,"sh_keyword",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/$/g,null,-2]],[[/\*\//g,"sh_comment",-2],[/(?:<?)[A-Za-z0-9_\.\/\-_~]+@[A-Za-z0-9_\.\/\-_~]+(?:>?)|(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_~]+(?:>?)/g,"sh_url",-1],[/<\?xml/g,"sh_preproc",2,1],[/<!DOCTYPE/g,"sh_preproc",4,1],[/<!--/g,"sh_comment",5],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",6,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,"sh_keyword",6,1],[/@[A-Za-z]+/g,"sh_type",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/\*\//g,"sh_comment",-2],[/(?:<?)[A-Za-z0-9_\.\/\-_~]+@[A-Za-z0-9_\.\/\-_~]+(?:>?)|(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_~]+(?:>?)/g,"sh_url",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/\}/g,"sh_cbracket",-2],[/\/\/\//g,"sh_comment",1],[/\/\//g,"sh_comment",7],[/\/\*\*/g,"sh_comment",8],[/\/\*/g,"sh_comment",9],[/[A-Za-z0-9_-]+[ \t]*:/g,"sh_property",-1],[/[.%A-Za-z0-9_-]+/g,"sh_value",-1],[/#(?:[A-Za-z0-9_]+)/g,"sh_string",-1]]];

/* HTML language (http://shjs.sourceforge.net/lang/sh_html.min.js) */
if(!this.sh_languages){this.sh_languages={}}sh_languages.html=[[[/<\?xml/g,"sh_preproc",1,1],[/<!DOCTYPE/g,"sh_preproc",3,1],[/<!--/g,"sh_comment",4],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",5,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,"sh_keyword",5,1]],[[/\?>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",2]],[[/\\(?:\\|")/g,null,-1],[/"/g,"sh_string",-2]],[[/>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",2]],[[/-->/g,"sh_comment",-2],[/<!--/g,"sh_comment",4]],[[/(?:\/)?>/g,"sh_keyword",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",2]]];

/* Javascript language (http://shjs.sourceforge.net/lang/sh_javascript.min.js) */
if(!this.sh_languages){this.sh_languages={}}sh_languages.javascript=[[[/\/\/\//g,"sh_comment",1],[/\/\//g,"sh_comment",7],[/\/\*\*/g,"sh_comment",8],[/\/\*/g,"sh_comment",9],[/\b(?:abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with)\b/g,"sh_keyword",-1],[/(\+\+|--|\)|\])(\s*)(\/=?(?![*\/]))/g,["sh_symbol","sh_normal","sh_symbol"],-1],[/(0x[A-Fa-f0-9]+|(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?)(\s*)(\/(?![*\/]))/g,["sh_number","sh_normal","sh_symbol"],-1],[/([A-Za-z$_][A-Za-z0-9$_]*\s*)(\/=?(?![*\/]))/g,["sh_normal","sh_symbol"],-1],[/\/(?:\\.|[^*\\\/])(?:\\.|[^\\\/])*\/[gim]*/g,"sh_regexp",-1],[/\b[+-]?(?:(?:0x[A-Fa-f0-9]+)|(?:(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?))u?(?:(?:int(?:8|16|32|64))|L)?\b/g,"sh_number",-1],[/"/g,"sh_string",10],[/'/g,"sh_string",11],[/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,"sh_symbol",-1],[/\{|\}/g,"sh_cbracket",-1],[/\b(?:Math|Infinity|NaN|undefined|arguments)\b/g,"sh_predef_var",-1],[/\b(?:Array|Boolean|Date|Error|EvalError|Function|Number|Object|RangeError|ReferenceError|RegExp|String|SyntaxError|TypeError|URIError|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|isNaN|parseFloat|parseInt)\b/g,"sh_predef_func",-1],[/(?:[A-Za-z]|_)[A-Za-z0-9_]*(?=[ \t]*\()/g,"sh_function",-1]],[[/$/g,null,-2],[/(?:<?)[A-Za-z0-9_\.\/\-_~]+@[A-Za-z0-9_\.\/\-_~]+(?:>?)|(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_~]+(?:>?)/g,"sh_url",-1],[/<\?xml/g,"sh_preproc",2,1],[/<!DOCTYPE/g,"sh_preproc",4,1],[/<!--/g,"sh_comment",5],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",6,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,"sh_keyword",6,1],[/@[A-Za-z]+/g,"sh_type",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/\?>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/\\(?:\\|")/g,null,-1],[/"/g,"sh_string",-2]],[[/>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/-->/g,"sh_comment",-2],[/<!--/g,"sh_comment",5]],[[/(?:\/)?>/g,"sh_keyword",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/$/g,null,-2]],[[/\*\//g,"sh_comment",-2],[/(?:<?)[A-Za-z0-9_\.\/\-_~]+@[A-Za-z0-9_\.\/\-_~]+(?:>?)|(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_~]+(?:>?)/g,"sh_url",-1],[/<\?xml/g,"sh_preproc",2,1],[/<!DOCTYPE/g,"sh_preproc",4,1],[/<!--/g,"sh_comment",5],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",6,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,"sh_keyword",6,1],[/@[A-Za-z]+/g,"sh_type",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/\*\//g,"sh_comment",-2],[/(?:<?)[A-Za-z0-9_\.\/\-_~]+@[A-Za-z0-9_\.\/\-_~]+(?:>?)|(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_~]+(?:>?)/g,"sh_url",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/"/g,"sh_string",-2],[/\\./g,"sh_specialchar",-1]],[[/'/g,"sh_string",-2],[/\\./g,"sh_specialchar",-1]]];

/* Javascript DOM language (http://shjs.sourceforge.net/lang/sh_javascript_dom.min.js) */
if(!this.sh_languages){this.sh_languages={}}sh_languages.javascript_dom=[[[/\/\/\//g,"sh_comment",1],[/\/\//g,"sh_comment",7],[/\/\*\*/g,"sh_comment",8],[/\/\*/g,"sh_comment",9],[/\b(?:abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with)\b/g,"sh_keyword",-1],[/(\+\+|--|\)|\])(\s*)(\/=?(?![*\/]))/g,["sh_symbol","sh_normal","sh_symbol"],-1],[/(0x[A-Fa-f0-9]+|(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?)(\s*)(\/(?![*\/]))/g,["sh_number","sh_normal","sh_symbol"],-1],[/([A-Za-z$_][A-Za-z0-9$_]*\s*)(\/=?(?![*\/]))/g,["sh_normal","sh_symbol"],-1],[/\/(?:\\.|[^*\\\/])(?:\\.|[^\\\/])*\/[gim]*/g,"sh_regexp",-1],[/\b[+-]?(?:(?:0x[A-Fa-f0-9]+)|(?:(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?))u?(?:(?:int(?:8|16|32|64))|L)?\b/g,"sh_number",-1],[/"/g,"sh_string",10],[/'/g,"sh_string",11],[/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,"sh_symbol",-1],[/\{|\}/g,"sh_cbracket",-1],[/\b(?:Math|Infinity|NaN|undefined|arguments)\b/g,"sh_predef_var",-1],[/\b(?:Array|Boolean|Date|Error|EvalError|Function|Number|Object|RangeError|ReferenceError|RegExp|String|SyntaxError|TypeError|URIError|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|isNaN|parseFloat|parseInt)\b/g,"sh_predef_func",-1],[/\b(?:applicationCache|closed|Components|content|controllers|crypto|defaultStatus|dialogArguments|directories|document|frameElement|frames|fullScreen|globalStorage|history|innerHeight|innerWidth|length|location|locationbar|menubar|name|navigator|opener|outerHeight|outerWidth|pageXOffset|pageYOffset|parent|personalbar|pkcs11|returnValue|screen|availTop|availLeft|availHeight|availWidth|colorDepth|height|left|pixelDepth|top|width|screenX|screenY|scrollbars|scrollMaxX|scrollMaxY|scrollX|scrollY|self|sessionStorage|sidebar|status|statusbar|toolbar|top|window)\b/g,"sh_predef_var",-1],[/\b(?:alert|addEventListener|atob|back|blur|btoa|captureEvents|clearInterval|clearTimeout|close|confirm|dump|escape|find|focus|forward|getAttention|getComputedStyle|getSelection|home|moveBy|moveTo|open|openDialog|postMessage|print|prompt|releaseEvents|removeEventListener|resizeBy|resizeTo|scroll|scrollBy|scrollByLines|scrollByPages|scrollTo|setInterval|setTimeout|showModalDialog|sizeToContent|stop|unescape|updateCommands|onabort|onbeforeunload|onblur|onchange|onclick|onclose|oncontextmenu|ondragdrop|onerror|onfocus|onkeydown|onkeypress|onkeyup|onload|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onpaint|onreset|onresize|onscroll|onselect|onsubmit|onunload)\b/g,"sh_predef_func",-1],[/(?:[A-Za-z]|_)[A-Za-z0-9_]*(?=[ \t]*\()/g,"sh_function",-1]],[[/$/g,null,-2],[/(?:<?)[A-Za-z0-9_\.\/\-_~]+@[A-Za-z0-9_\.\/\-_~]+(?:>?)|(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_~]+(?:>?)/g,"sh_url",-1],[/<\?xml/g,"sh_preproc",2,1],[/<!DOCTYPE/g,"sh_preproc",4,1],[/<!--/g,"sh_comment",5],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",6,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,"sh_keyword",6,1],[/@[A-Za-z]+/g,"sh_type",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/\?>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/\\(?:\\|")/g,null,-1],[/"/g,"sh_string",-2]],[[/>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/-->/g,"sh_comment",-2],[/<!--/g,"sh_comment",5]],[[/(?:\/)?>/g,"sh_keyword",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/$/g,null,-2]],[[/\*\//g,"sh_comment",-2],[/(?:<?)[A-Za-z0-9_\.\/\-_~]+@[A-Za-z0-9_\.\/\-_~]+(?:>?)|(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_~]+(?:>?)/g,"sh_url",-1],[/<\?xml/g,"sh_preproc",2,1],[/<!DOCTYPE/g,"sh_preproc",4,1],[/<!--/g,"sh_comment",5],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",6,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,"sh_keyword",6,1],[/@[A-Za-z]+/g,"sh_type",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/\*\//g,"sh_comment",-2],[/(?:<?)[A-Za-z0-9_\.\/\-_~]+@[A-Za-z0-9_\.\/\-_~]+(?:>?)|(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_~]+(?:>?)/g,"sh_url",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/"/g,"sh_string",-2],[/\\./g,"sh_specialchar",-1]],[[/'/g,"sh_string",-2],[/\\./g,"sh_specialchar",-1]]];

/* URL language (http://shjs.sourceforge.net/lang/sh_url.min.js) */
if(!this.sh_languages){this.sh_languages={};}
sh_languages['url']=[[{'regex':/(?:<?)[A-Za-z0-9_\.\/\-_]+@[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'},{'regex':/(?:<?)[A-Za-z0-9_]+:\/\/[A-Za-z0-9_\.\/\-_]+(?:>?)/g,'style':'sh_url'}]];

/* XML language (http://shjs.sourceforge.net/lang/sh_xml.min.js) */
if(!this.sh_languages){this.sh_languages={}}sh_languages.xml=[[[/<\?xml/g,"sh_preproc",1,1],[/<!DOCTYPE/g,"sh_preproc",3,1],[/<!--/g,"sh_comment",4],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",5,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1]],[[/\?>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",2]],[[/\\(?:\\|")/g,null,-1],[/"/g,"sh_string",-2]],[[/>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",2]],[[/-->/g,"sh_comment",-2],[/<!--/g,"sh_comment",4]],[[/(?:\/)?>/g,"sh_keyword",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",2]]];/*
 * jQuery gridBuilder
 * Version 1.2 (26/10/2009)
 *
 * Copyright (c) 2009 Kilian Valkhof (kilianvalkhof.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
"use strict";
(function ($) {
    $.fn.gridBuilder = function (useroptions) {
        return this.each(function () {
            var $this = $(this);

            //init options
            var options = $.extend(
                {id: this.id},
                $.fn.gridBuilder.defaults,
                useroptions
            );

            if ( $.fn.gridBuilder.featureDetection() ) {
                // build canvas and context
                var gridCanvas = $.fn.gridBuilder.makeCanvas(options);
                var gridContext = gridCanvas.getContext("2d");

                // draw all lines and place them as background
                $.fn.gridBuilder.drawVertical(gridContext, options);
                $.fn.gridBuilder.drawHorizontal(gridContext, options);
                $.fn.gridBuilder.setBackground(this, gridCanvas, options);
            }
        });
    };

    //Provide defaults
    $.fn.gridBuilder.defaults = {
        color:          '#eee',
        secondaryColor: '#f9f9f9',
        vertical:       18,
        horizontal:     140,
        gutter:         40
    };


    $.fn.gridBuilder.featureDetection = function() {
        var elem = document.createElement('canvas');
        return !!(elem.getContext && elem.getContext('2d'));
    };

    // build a canvas the size of the chosen element
    $.fn.gridBuilder.makeCanvas = function (options) {
        var canvas = document.createElement('canvas');
        canvas.id = "gridCanvasFor" + options.id;
        canvas.height = options.vertical;
        canvas.width = options.horizontal + options.gutter;
        return canvas;
    };

    // draw the vertical lines
    $.fn.gridBuilder.drawVertical = function (gridContext, options) {
        if (options.horizontal) {
            gridContext.beginPath();
            for (var x = - (options.gutter/2) - 0.5; x <= options.horizontal + options.gutter; x += options.horizontal) {
                $.fn.gridBuilder.drawSingleLine(gridContext, x, 0, x, options.vertical);
                if (options.gutter > 0) {
                    x += options.gutter;
                    $.fn.gridBuilder.drawSingleLine(gridContext, x, 0, x, options.vertical);
                }
            }
            $.fn.gridBuilder.draw(gridContext, options.color);

            //draw secondary lines
            if (options.secondaryColor) {
                var xs = (options.gutter/2) + (options.horizontal / 2) - 0.5;
                gridContext.beginPath();
                $.fn.gridBuilder.drawSingleLine(gridContext, xs, 0, xs, options.vertical);
                $.fn.gridBuilder.draw(gridContext, options.secondaryColor);
            }
        }
    };

    // draw the horizontal lines
    $.fn.gridBuilder.drawHorizontal = function (gridContext, options) {
        if (options.vertical) {
            var y = options.vertical - 0.5;
            gridContext.beginPath();
            $.fn.gridBuilder.drawSingleLine(gridContext, 0, y, options.horizontal + options.gutter, y);
            $.fn.gridBuilder.draw(gridContext, options.color);

            //draw secondary lines
            if (options.secondaryColor) {
                var ys = (options.vertical / 2) - 0.5;
                gridContext.beginPath();
                $.fn.gridBuilder.drawSingleLine(gridContext, 0, ys, options.horizontal + options.gutter, ys);
                $.fn.gridBuilder.draw(gridContext, options.secondaryColor);
            }
        }
    };

    // draw single line
    $.fn.gridBuilder.drawSingleLine = function (gridContext, x, y,newx,newy) {
        gridContext.moveTo(x, y);
        gridContext.lineTo(newx, newy);
    };
    // draw elements on the canvas
    $.fn.gridBuilder.draw = function (gridContext, color) {
        gridContext.strokeStyle = color;
        gridContext.stroke();
    };

    // set as background
    $.fn.gridBuilder.setBackground = function (element, gridCanvas, options) {
        var canvasData = gridCanvas.toDataURL();
        $(element).css({
            "background-image": "url(" + canvasData + ")",
            "background-repeat":"repeat"
        });
    };

    // remove canvas element, get rid of background image
    $.fn.destroyGrid = function (useroptions) {
        return this.each(function () {
            var $this = $(this);
            $this.css({"background-image": "none"});
            $("gridCanvasFor" + $this.id).remove();
        });
    };
}(jQuery));

/**
 * Accessible Tabs - jQuery plugin for accessible, unobtrusive tabs
 * Build to seemlessly work with the CCS-Framework YAML (yaml.de) not depending on YAML though
 * @requires jQuery - tested with 1.7 and 1.4.2 but might as well work with older versions
 *
 * english article: http://blog.ginader.de/archives/2009/02/07/jQuery-Accessible-Tabs-How-to-make-tabs-REALLY-accessible.php
 * german article: http://blog.ginader.de/archives/2009/02/07/jQuery-Accessible-Tabs-Wie-man-Tabs-WIRKLICH-zugaenglich-macht.php
 *
 * code: http://github.com/ginader/Accessible-Tabs
 * please report issues at: http://github.com/ginader/Accessible-Tabs/issues
 *
 * Copyright (c) 2007 Dirk Ginader (ginader.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 1.9.4
 *
 * History:
 * * 1.0 initial release
 * * 1.1 added a lot of Accessibility enhancements
 * * * rewrite to use "fn.extend" structure
 * * * added check for existing ids on the content containers to use to proper anchors in the tabs
 * * 1.1.1 changed the headline markup. thanks to Mike Davies for the hint.
 * * 1.5 thanks to Dirk Jesse, Ansgar Hein, David Maciejewski and Mike West for commiting patches to this release
 * * * new option syncheights that syncs the heights of the tab contents when the SyncHeight plugin
 * *   is available http://blog.ginader.de/dev/jquery/syncheight/index.php
 * * * fixed the hardcoded current class
 * * * new option tabsListClass to be applied to the generated list of tabs above the content so lists
 * *   inside the tabscontent can be styled differently
 * * * added clearfix and tabcounter that adds a class in the schema "tabamount{number amount of tabs}"
 * *   to the ul containg the tabs so one can style the tabs to fit 100% into the width
 * * * new option "syncHeightMethodName" fixed issue: http://github.com/ginader/Accessible-Tabs/issues/2/find
 * * * new Method showAccessibleTab({index number of the tab to show starting with 0})  fixed issue: http://github.com/ginader/Accessible-Tabs/issues/3/find
 * * * added support for the Cursor Keys to come closer to the WAI ARIA Tab Panel Best Practices http://github.com/ginader/Accessible-Tabs/issues/1/find
 * * 1.6
 * * * new option "saveState" to allow tabs remember their selected state using cookies requires the cookie plugin: http://plugins.jquery.com/project/Cookie
 * * * changed supported jquery version to 1.4.2 to make sure it's future compatible
 * * * new option "autoAnchor" which allows to add ID's to headlines in the tabs markup that allow direct linking into a tab i.e.: file.html#headlineID
 * * 1.7
 * * * new option "pagination" that adds links to show the next/previous tab. This adds the following markup to each tab for you to style:
 <ul class="pagination">
 <li class="previous"><a href="#{the-id-of-the-previous-tab}"><span>{the headline of the previous tab}</span></a></li>
 <li class="next"><a href="#{the-id-of-the-next-tab}"><span>{the headline of the previous tab}</span></a></li>
 </ul>
 * * 1.8
 * * * new option "position" can be 'top' or 'bottom'. Defines where the tabs list is inserted.
 * * 1.8.1
 * * * Bugfix for broken pagination in ie6 and 7: Selector and object access modified by Daniel K�nt�s (www.MilkmanMedia.de). Thanks to Carolin Moll for the report.
 * * 1.8.2
 * * * Bugfix for issue described by Sunshine here: http://blog.ginader.de/archives/2009/02/07/jQuery-Accessible-Tabs-How-to-make-tabs-REALLY-accessible.php#c916
 * * 1.8.3
 * * * Bugfix by Michael Schulze: Only change current class in tab navigation and not in all unordered lists inside the tabs.
 * * 1.9
 * * * new method showAccessibleTabSelector({valid jQuery selector of the tab to show}) that allows the opening of tabs \
 * * * by jQuery Selector instead of the index in showAccessibleTab() fixing issue https://github.com/ginader/Accessible-Tabs/issues/15
 * * 1.9.1 by Michael Schulze:
 * * * firstNavItemClass and lastNavItemClass to define a custom classname on the first and last tab
 * * * wrapInnerNavLinks: inner wrap for a-tags in tab navigation.
 * * 1.9.2
 * * * Bugfix by Dirk Jesse: fixing an issue that happened when passing multiple selectors to the init call instead of one
 * * * Bugfix that fixes a reset of the tabs counter when accessibleTabs() was called more than once on a page
 * * 1.9.3
 * * * Bugfix by Norm: before, when cssClassAvailable was true, all of the tabhead elements had to have classes or they wouldn't get pulled out into tabs.
 * * * This commit fixes this assumption, as I only want classes on some elements https://github.com/ginader/Accessible-Tabs/pull/25
 * * 1.9.4 Bugfix by Patrick Bruckner to fix issue with Internet Explorer using jQuery 1.7 https://github.com/ginader/Accessible-Tabs/issues/26
 */


(function($) {
    var debugMode = true;
    $.fn.extend({
        // We assume there could be multiple sets of tabs on a page, so,
        // the unique id for each invididual tab's heading is identified with params q and r (e.g., id="accessibletabscontent0-2")
        getUniqueId: function(p, q, r){
            if (r===undefined) {r='';} else {r='-'+r;}
            return p + q + r;
        },
        accessibleTabs: function(config) {
            var defaults = {
                wrapperClass: 'content', // Classname to apply to the div that is wrapped around the original Markup
                currentClass: 'current', // Classname to apply to the LI of the selected Tab
                tabhead: 'h4', // Tag or valid Query Selector of the Elements to Transform the Tabs-Navigation from (originals are removed)
                tabheadClass: 'tabhead', // Classname to apply to the target heading element for each tab div
                tabbody: '.tabbody', // Tag or valid Query Selector of the Elements to be treated as the Tab Body
                fx:'show', // can be "fadeIn", "slideDown", "show"
                fxspeed: 'normal', // speed (String|Number): "slow", "normal", or "fast") or the number of milliseconds to run the animation
                currentInfoText: 'current tab: ', // text to indicate for screenreaders which tab is the current one
                currentInfoPosition: 'prepend', // Definition where to insert the Info Text. Can be either "prepend" or "append"
                currentInfoClass: 'current-info', // Class to apply to the span wrapping the CurrentInfoText
                tabsListClass:'tabs-list', // Class to apply to the generated list of tabs above the content
                syncheights:false, // syncs the heights of the tab contents when the SyncHeight plugin is available http://blog.ginader.de/dev/jquery/syncheight/index.php
                syncHeightMethodName:'syncHeight', // set the Method name of the plugin you want to use to sync the tab contents. Defaults to the SyncHeight plugin: http://github.com/ginader/syncHeight
                cssClassAvailable:false, // Enable individual css classes for tabs. Gets the appropriate class name of a tabhead element and apply it to the tab list element. Boolean value
                saveState:false, // save the selected tab into a cookie so it stays selected after a reload. This requires that the wrapping div needs to have an ID (so we know which tab we're saving)
                autoAnchor:false, // will move over any existing id of a headline in tabs markup so it can be linked to it
                pagination:false, // adds buttons to each tab to switch to the next/previous tab
                position:'top', // can be 'top' or 'bottom'. Defines where the tabs list is inserted.
                wrapInnerNavLinks: '', // inner wrap for a-tags in tab navigation. See http://api.jquery.com/wrapInner/ for further informations
                firstNavItemClass: 'first', // Classname of the first list item in the tab navigation
                lastNavItemClass: 'last' // Classname of the last list item in the tab navigation
            };
            var keyCodes = {
                37 : -1, //LEFT
                38 : -1, //UP
                39 : +1, //RIGHT
                40 : +1 //DOWN
            };
            var positions = {
                top : 'prepend',
                bottom : 'append'
            };
            this.options = $.extend(defaults, config);

            var tabsCount = 0;
            if($("body").data('accessibleTabsCount') !== undefined){
                tabsCount = $("body").data('accessibleTabsCount');
            }
            $("body").data('accessibleTabsCount',this.size()+tabsCount);

            var o = this;
            return this.each(function(t) {
                var el = $(this);
                var list = '';
                var tabCount = 0;
                var ids = [];

                $(el).wrapInner('<div class="'+o.options.wrapperClass+'"></div>');

                $(el).find(o.options.tabhead).each(function(i){
                    var id = '';
                    elId = $(this).attr('id');
                    if(elId){
                        // Skip this item if it already exists.
                        if(elId.indexOf('accessibletabscontent') === 0) {
                            return;
                        }
                        id =' id="'+elId+'"';
                    }
                    var tabId = o.getUniqueId('accessibletabscontent', tabsCount+t, i);//get a unique id to assign to this tab's heading
                    var navItemId = o.getUniqueId('accessibletabsnavigation', tabsCount+t, i);//get a unique id for this navigation item
                    ids.push(tabId);
                    if(o.options.cssClassAvailable === true) {
                        var cssClass = '';
                        if($(this).attr('class')) {
                            cssClass = $(this).attr('class');
                            cssClass = ' class="'+cssClass+'"';
                        }
                        list += '<li id="'+navItemId+'"><a'+id+''+cssClass+' href="#'+tabId+'">'+$(this).html()+'</a></li>';
                    } else {
                        list += '<li id="'+navItemId+'"><a'+id+' href="#'+tabId+'">'+$(this).html()+'</a></li>';
                    }
                    $(this).attr({"id": tabId, "class": o.options.tabheadClass, "tabindex": "-1"});//assign the unique id and the tabheadClass class name to this tab's heading
                    tabCount++;
                });

                if (o.options.syncheights && $.fn[o.options.syncHeightMethodName]) {
                    $(el).find(o.options.tabbody)[o.options.syncHeightMethodName]();
                    $(window).resize(function(){
                        $(el).find(o.options.tabbody)[o.options.syncHeightMethodName]();
                    });
                }

                // Ensure that the call to setup tabs is re-runnable
                var tabs_selector = '.' + o.options.tabsListClass;
                if(!$(el).find(tabs_selector).length) {
                    $(el)[positions[o.options.position]]('<ul class="clearfix '+o.options.tabsListClass+' tabamount'+tabCount+'"></ul>');
                }

                $(el).find(tabs_selector).append(list);

                // initial show first content block and hide the others
                var content = $(el).find(o.options.tabbody);
                if (content.length > 0) {
                    $(content).hide();
                    $(content[0]).show();
                }
                $(el).find("ul."+o.options.tabsListClass+">li:first").addClass(o.options.currentClass).addClass(o.options.firstNavItemClass)
                    .find('a')[o.options.currentInfoPosition]('<span class="'+o.options.currentInfoClass+'">'+o.options.currentInfoText+'</span>')
                    .parents("ul."+o.options.tabsListClass).children('li:last').addClass(o.options.lastNavItemClass);

                if (o.options.wrapInnerNavLinks) {
                    $(el).find('ul.'+o.options.tabsListClass+'>li>a').wrapInner(o.options.wrapInnerNavLinks);
                }

                $(el).find('ul.'+o.options.tabsListClass+'>li>a').each(function(i){
                    $(this).click(function(event){
                        event.preventDefault();
                        el.trigger("showTab.accessibleTabs", [$(event.target)]);
                        if(o.options.saveState && $.cookie){
                            $.cookie('accessibletab_'+el.attr('id')+'_active',i);
                        }
                        $(el).find('ul.'+o.options.tabsListClass+'>li.'+o.options.currentClass).removeClass(o.options.currentClass)
                            .find("span."+o.options.currentInfoClass).remove();
                        $(this).blur();
                        $(el).find(o.options.tabbody+':visible').hide();
                        $(el).find(o.options.tabbody).eq(i)[o.options.fx](o.options.fxspeed);
                        $(this)[o.options.currentInfoPosition]('<span class="'+o.options.currentInfoClass+'">'+o.options.currentInfoText+'</span>')
                            .parent().addClass(o.options.currentClass);
                        //now, only after writing the currentInfoText span to the tab list link, set focus to the tab's heading
                        $($(this).attr("href"),true).focus().keyup(function(event){
                            if(keyCodes[event.keyCode]){
                                o.showAccessibleTab(i+keyCodes[event.keyCode]);
                                $(this).unbind( "keyup" );
                            }
                        });

                        // $(el).find('.accessibletabsanchor').keyup(function(event){
                        //     if(keyCodes[event.keyCode]){
                        //         o.showAccessibleTab(i+keyCodes[event.keyCode]);
                        //     }
                        // });


                    });

                    $(this).focus(function(event){
                        $(document).keyup(function(event){
                            if(keyCodes[event.keyCode]){
                                o.showAccessibleTab(i+keyCodes[event.keyCode]);
                            }
                        });
                    });
                    $(this).blur(function(event){
                        $(document).unbind( "keyup" );
                    });

                });

                if(o.options.saveState && $.cookie){
                    var savedState = $.cookie('accessibletab_'+el.attr('id')+'_active');
                    debug($.cookie('accessibletab_'+el.attr('id')+'_active'));
                    if(savedState !== null){
                        o.showAccessibleTab(savedState,el.attr('id'));
                    }
                }

                if(o.options.autoAnchor && window.location.hash){
                    var anchorTab = $('.'+o.options.tabsListClass).find(window.location.hash);
                    if(anchorTab.size()){
                        anchorTab.click();
                    }
                }

                if(o.options.pagination){
                    var m = '<ul class="pagination">';
                    m +='    <li class="previous"><a href="#{previousAnchor}"><span>{previousHeadline}</span></a></li>';
                    m +='    <li class="next"><a href="#{nextAnchor}"><span>{nextHeadline}</span></a></li>';
                    m +='</ul>';
                    var tabs = $(el).find('.tabbody');
                    var tabcount = tabs.size();
                    tabs.each(function(idx){
                        $(this).append(m);
                        var next = idx+1;
                        if(next>=tabcount){next = 0;}
                        var previous = idx-1;
                        if(previous<0){previous = tabcount-1;}
                        var p = $(this).find('.pagination');
                        var previousEl = p.find('.previous');
                        previousEl.find('span').text($('#'+ids[previous]).text());
                        previousEl.find('a').attr('href','#'+ids[previous])
                            .click(function(event){
                                event.preventDefault();
                                $(el).find('.tabs-list a').eq(previous).click();
                            });
                        var nextEl = p.find('.next');
                        nextEl.find('span').text($('#'+ids[next]).text());
                        nextEl.find('a').attr('href','#'+ids[next])
                            .click(function(event){
                                event.preventDefault();
                                $(el).find('.tabs-list a').eq(next).click();
                            });
                    });
                }
            });
        },
        showAccessibleTab: function(index,id){
            debug('showAccessibleTab');
            var o = this;
            if(id) {
                var el = $('#'+id);
                var links = el.find('ul.'+o.options.tabsListClass+'>li>a');
                el.trigger("showTab.accessibleTabs", [links.eq(index)]);
                links.eq(index).click();
            } else {
                return this.each(function() {
                    var el = $(this);
                    el.trigger("showTab.accessibleTabs");
                    var links = el.find('ul.'+o.options.tabsListClass+'>li>a');
                    el.trigger("showTab.accessibleTabs", [links.eq(index)]);
                    links.eq(index).click();
                });
            }
        },
        showAccessibleTabSelector: function(selector){
            debug('showAccessibleTabSelector');
            var o = this;
            var el = $(selector);
            if(el){
                if(el.get(0).nodeName.toLowerCase() == 'a'){
                    el.click();
                }else{
                    debug('the selector of a showAccessibleTabSelector() call needs to point to a tabs headline!');
                }
            }
        }
    });
    // private Methods
    function debug(msg,info){
        if(debugMode && window.console && window.console.log){
            if(info){
                window.console.log(info+': ',msg);
            }else{
                window.console.log(msg);
            }
        }
    }
})(jQuery);
/**
 * syncHeight - jQuery plugin to automagically Snyc the heights of columns
 * Made to seemlessly work with the CCS-Framework YAML (yaml.de)
 * @requires jQuery v1.0.3
 *
 * http://blog.ginader.de/dev/syncheight/
 *
 * Copyright (c) 2007-2009
 * Dirk Ginader (ginader.de)
 * Dirk Jesse (yaml.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Version: 1.2
 *
 * Usage:
 $(window).load(function(){
 $('p').syncHeight();
 });
 */

(function($) {
    var getHeightProperty = function() {
        var browser_id = 0;
        var property = [
            // To avoid content overflow in synchronised boxes on font scaling, we
            // use 'min-height' property for modern browsers ...
            ['min-height','0px'],
            // and 'height' property for Internet Explorer.
            ['height','1%']
        ];

        // check for IE6 ...
        if($.browser.msie && $.browser.version < 7){
            browser_id = 1;
        }

        return { 'name': property[browser_id][0],
            'autoheightVal': property[browser_id][1] };
    };

    $.getSyncedHeight = function(selector) {
        var max = 0;
        var heightProperty = getHeightProperty();
        // get maximum element height ...
        $(selector).each(function() {
            // fallback to auto height before height check ...
            $(this).css(heightProperty.name, heightProperty.autoheightVal);
            var val = $(this).height();
            if(val > max){
                max = val;
            }
        });
        return max;
    };

    $.fn.syncHeight = function(config) {
        var defaults = {
            updateOnResize: false,	// re-sync element heights after a browser resize event (useful in flexible layouts)
            height: false
        };
        var options = $.extend(defaults, config);

        var e = this;

        var max = 0;
        var heightPropertyName = getHeightProperty().name;

        if(typeof(options.height) === "number") {
            max = options.height;
        } else {
            max = $.getSyncedHeight(this);
        }
        // set synchronized element height ...
        $(this).each(function() {
            $(this).css(heightPropertyName, max+'px');
        });

        // optional sync refresh on resize event ...
        if (options.updateOnResize === true) {
            $(window).resize(function(){
                $(e).syncHeight();
            });
        }
        return this;
    };
})(jQuery);$(document).ready(function() {

    var domscripts = {

        init: function init () {

            var self = this;

            self.installStickyMenu();
            self.installTabs();
            self.installSyntaxHighlighting();
            self.installGrid();
            self.installFormSwitcher();
        },

        installStickyMenu: function installStickyMenu () {

            var header      = $('body > header'),
                headings    = $('#main h2'),
                nav         = $('nav#level2'),
                stickyClass = 'fix';

            if (nav.find('.ym-hlist').length > 0 ) {

                // install smallscreen menu
                var menu =	'<li><label for="ym-smnav" style="padding: 0 0.5em; color: rgba(255,255,255,.8)">Navigation:</label> '+
                    '<select id="ym-smnav" style="font-size: 16px;"><option value="0" selected="selected" disabled="disabled">Go to ...</option>';
                var items = nav.find('a');
                $.each(items, function(key){
                    menu += '<option data-target="'+$(this).attr('href')+'">'+$(this).text()+'</option>';
                });
                menu += '</select></li>';

                var smnav = $(menu).appendTo(nav.find('ul')).hide();

                $(window).bind('resize',function(){
                    var width = $(window).width();

                    if (width > 740) {
                        smnav.siblings().show();
                        smnav.hide();
                    } else {
                        smnav.siblings().hide();
                        smnav.show();
                    }
                });

                $(smnav).bind('change', function(){
                    var target = $(this).find('option:selected').data('target');
                    nav.find('a[href='+target+']').trigger('click');
                });

                $(document).bind('scroll',function(){
                    var hOffset = header.offset().top+header.height(),
                        top     = $(document).scrollTop(),
                        trigger = false;

                    // make it sticky ...
                    if (hOffset < top) {
                        if (nav.data(stickyClass) !== true) {
                            nav.addClass(stickyClass).data(stickyClass,true);
                        }
                    } else {
                        if (nav.data(stickyClass) !== false) {
                            nav.removeClass(stickyClass).data(stickyClass,false);
                        }
                    }

                    var nOffset = nav.height();

                    // adjust active menu-item from scroll-value
                    $.each(headings, function(key){
                        var id        = '#'+$(this).attr('id'),
                            offset    = $(this).offset().top,
                            pos       = offset - top,
                            targetPos = 0;

                        if (nav.hasClass(stickyClass) === true) {
                            targetPos = 2*nav.height();
                        }

                        if (pos > targetPos) {
                            nav.find('a[href="'+id+'"]').parent().prev().addClass('active').siblings().removeClass('active');
                            return false;
                        } else if (pos < targetPos && pos > targetPos - nOffset) {
                            nav.find('a[href="'+id+'"]').parent().addClass('active').siblings().removeClass('active');
                            return false;
                        }
                    });
                });

                // initial check for scroll-status ...
                $(document).trigger('scroll');
                $(window).trigger('resize');

                if ($('body').hasClass('doc') === true) {

                    var stateObj = { page: "index" };

                    // jump to a named anchor ...
                    $('#level2 a').bind('click', function(event){
                        event.preventDefault();

                        var id      = $(this).attr('href'),
                            pos     = $(id).offset().top,
                            nHeight = nav.height() + 6; // 6px whitespace

                        // set active menu-item ...
                        $(this).parent()
                            .addClass('active')
                            .siblings()
                            .removeClass('active');

                        $(id).focus();

                        // adjust scroll-value
                        if (nav.hasClass(stickyClass) === true) {
                            $(document).scrollTop(pos-nHeight);
                        } else {
                            $(document).scrollTop(pos-2*nHeight);
                        }
                        // update URL id fragment
                        history.pushState(stateObj, "docs", "index.html"+id);
                    });
                }
            }
        },

        installTabs: function installTabs () {

            // standard behavoir in YAML docs
            $('.jquery_tabs:not([data-sync])').accessibleTabs({
                fx:"show",
                fxspeed: '',
                syncheights: false,
                tabhead: 'h5',
                tabbody:'.tab-content'
            });

            // "accessible tabs" sync example
            $('.jquery_tabs[data-sync="true"]').accessibleTabs({
                fx:"show",
                fxspeed: '',
                syncheights: true,
                tabhead: 'h5',
                tabbody:'.tab-content'
            });
        },

        installSyntaxHighlighting: function installSyntaxHighlighting () {
            var highlightStyle = "peachpuff";

            if (jQuery.fn.snippet) {
                $("pre.htmlCode").snippet("html", {style: highlightStyle});
                $("pre.cssCode").snippet("css", {style: highlightStyle});
                $("pre.jsCode").snippet("javascript", {style: highlightStyle});
            }
        },

        installGrid: function installGrid () {

            // vertical rhythm lines for typography section ...
            if (jQuery.fn.gridBuilder) {
                $(".v-grid").gridBuilder({
                    color: '#eee', // color of the primary gridlines
                    secondaryColor: '#f9f9f9', // color of the secondary gridlines
                    vertical: 21, // height of the vertical rhythm
                    horizontal: 2000, // width of horizontal strokes
                    gutter: 0 // width of the gutter between strokes
                });
            }
        },

        installFormSwitcher: function installFormSwitcher () {
            $('#formswitch [type="checkbox"]').prop('checked', true);
            $('#formswitch [type="radio"]:first').prop('checked', true);

            $('#formswitch').change(function(event){
                var target = event.target,
                    type   = $(target).data('type');

                if ($(target).attr('type') == 'radio') {
                    $('#demo-form1, #demo-form2').removeClass('ym-columnar');
                    $('#demo-form1, #demo-form2').removeClass('ym-full');
                    $('#demo-form1, #demo-form2').addClass(type);
                }
                if ($(target).attr('type') == 'checkbox') {
                    if ($(target).prop('checked') === true) {
                        $('#demo-form1, #demo-form2').addClass('linearize-form');
                    } else {
                        $('#demo-form1, #demo-form2').removeClass('linearize-form');
                    }
                }
            });
        }
    };

    domscripts.init();
});

//check for deep links
$(window).load(function() {
    var fragment = location.href.split('#'),
        nav      = $('nav#level2');

    if (fragment.length > 0) {
        $(nav.find('a[href="#'+fragment[1]+'"]')).trigger('click');
    }
});
